$(function () {
    share();
    var partnerOpenid=$.getUrlParam('partnerOpenid');
    //TODO:修改个人信息
    $.ajax({
        url:host+'//CMSAPI/GetPartner?openid='+partnerOpenid+'&cid='+cid,
        type:'GET',
        success:function(data){
            if(data.state){
                var RealName=data.data.RealName||'';
                // var addr=data.data.addr||'';
                var Phone=data.data.Phone||'';
                var Company=data.data.Company||'';
                var Position=data.data.Position||'';
                var industry=data.data.industry||'';
                var html='<li><i class="fa fa-address-book-o" aria-hidden="true"></i>&nbsp;&nbsp;姓名：'+RealName+'</li>'
                html+='    <li><i class="fa fa-phone" aria-hidden="true"></i>&nbsp;&nbsp;电话：<a href="tel:'+Phone+'">'+Phone+'</a></li>'
                html+='    <li><i class="fa fa-tags" aria-hidden="true"></i>&nbsp;&nbsp;品牌：<a href="tel:'+Phone+'">'+Company+'</a></li>'
                html+='    <li><i class="fa fa-location-arrow" aria-hidden="true"></i>&nbsp;&nbsp;行业：<a href="tel:'+Phone+'">'+industry+'</a></li>'
                html+='    <li><i class="fa fa-suitcase" aria-hidden="true"></i>&nbsp;&nbsp;职位：<a href="tel:'+Phone+'">'+Position+'</a></li>'
                $('.partnerDetail').append(html);
            }
        }
    })
    //TODO:添加列表
    var index=0;
    var size=10;
    var message=0;
    // var fid=ddid||did;//第一次进来时间初始化的第一列表id  first id
    $('section').dropload({
        scrollArea:window,
        distance:50,
        domUp:{
            domClass : 'dropload-up',
            domRefresh : '<div class="dropload-refresh">↓下拉刷新</div>',
            domUpdate : '<div class="dropload-update">↑释放更新</div>',
            domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'
        },
        domDown:{
            domClass : 'dropload-down',
            domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
            domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData : '<div class="dropload-noData">已经到底了，别扯了</div>'
        },
        loadDownFn:function(me){
            index++;
            message++;
            $.ajax({
                url:host+'/CMSAPI/GetPartnerList?openid='+partnerOpenid+'&cid='+cid+'&index='+index+'&size='+size,
                type:'GET',
                dataType:'JSON',
                success:function(data){
                    if(data.state){
                        var msgNum =Math.ceil(data.data.count/size);
                        console.log(msgNum)
                        console.log(message)
                        if (message <=msgNum){
                            console.log(1)
                            var html3='';
                            var list3=data.data.CustomerList;
                            $.each(list3,function(i,obj){
                                var RealName=obj.RealName||'';
                                var dataId=obj.id;
                                var openid=obj.openid;
                                var isOnline = obj.online
                                // var imgUrl=obj.images.length>=1?obj.images[0].URL:'';
                                var Phone=obj.Phone||'';
                                var addr=obj.addr||'0';
                                html3+= isOnline?'<li><a href="client-detail-online.html?did='+openid+'">': '<li><a href="clientDetail.html?did='+dataId+'">'
                                html3+='    <div class="name">'+RealName+'</div>'
                                html3+='    <div class="phone">'+Phone+'</div>'
                                html3+='    <div class="addr">'+addr+'</div>'
                                html3+='    <i class="fa fa-chevron-right" aria-hidden="true"></i>'
                                html3+='</a></li>'
                            });
                            $('.tableMain').append(html3);
                        }else {
                            me.lock();
                            me.noData();
                        }
                    }else {
                        alert('网络繁忙，请稍后重试！')
                    }
                    me.resetload();
                }
            })
        }
        // loadUpFn:function(me){
        //     location.reload();
        //     me.resetload();
        // }
    });
    //TODO:添加到访记录
    // $('.tableMain').on('click','li',function(){
    //     var id=$(this).attr('data-id');
    //     window.location.href='clientDetail.html?did='+id;
    // })
})
